﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Weber.CS3280.Interfaces;

namespace Weber.CS3280.UI.ViewModels
{
	public abstract class ViewModelBase : INotifyPropertyChanged, ICustomCleanup
	{
		private string _windowTitle;

		/// <summary>
		/// Gets or sets the Window Title for this ViewModel (if the window is paying attention to it)
		/// </summary>
		public string WindowTitle
		{
			get { return _windowTitle; }
			set
			{
				if (_windowTitle == value)
					return;
				_windowTitle = value;
				NotifyPropertyChanged("WindowTitle");
			}
		}

		public virtual void DoCleanup()
		{
		}

		/// <summary>
		/// Optionally compares the other view model to this instance in order to determine if the new model is distinct from this one when 
		/// the view model is used in a window type that only allows a single instance of a given data set
		/// </summary>
		/// <param name="compareToModel">Reference to the view model to be compared</param>
		/// <returns>True if the new view model is allowed to create a new view</returns>
		public virtual bool AllowNewView(ViewModelBase compareToModel)
		{
			return true;
		}

		public event PropertyChangedEventHandler PropertyChanged;

		/// <summary>
		/// Raises the PropertyChanged event.
		/// </summary>
		/// <param name="propertyName">Name of the Property that was changed</param>
		/// <param name="passThroughSender">Optional reference to another sender if this instance is not intended to be the sender</param>
		protected virtual void NotifyPropertyChanged(string propertyName, object passThroughSender = null)
		{
			if (PropertyChanged != null)
				PropertyChanged(passThroughSender ?? this, new PropertyChangedEventArgs(propertyName));
		}
	}
}
